using System;
using System.Collections.Generic;
using System.Text;
using iTunesLib;
using System.IO;

namespace DeleteOneStar
{
    class Program
    {
        static void Main(string[] args)
        {
            bool printOnly = false;
            if (args.Length > 0 && args[0] == "print")
                printOnly = true;

            iTunesLib.iTunesApp app = new iTunesLib.iTunesAppClass();
            IITTrackCollection tracks = app.LibraryPlaylist.Tracks;
            for (int i = 1; i <= tracks.Count; i++)
            {
                try
                {
                    IITFileOrCDTrack track = (IITFileOrCDTrack)tracks[i];
                    if (track.Rating == 20)
                    {
                        string loc = track.Location;
                        string key = track.Location.ToUpper();
                        Console.WriteLine("Del: " + loc);
                        if (!printOnly)
                        {
                            if (File.Exists(loc))
                                File.Delete(loc);
                            track.Delete();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Ex: " + ex.Message);
                }
            }
        }
    }
}
